package com.wxj.bank.module.page;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.List;

/**
 * @author shengtao
 * @Description:
 * @date 2019/02/19 16:06
 */
public class PageBean<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    //当前页
    private Integer currentPage = 1;

    //每页显示总条数
    private Integer pageSize = 5;

    //总条数
    private Long totalNum;

    //分页结果
    private List<T> items;

    public PageBean() {
    }

    public PageBean(Page page) {
        this.currentPage = page.getPageNum();
        this.pageSize = page.getPageSize();
        this.totalNum = page.getTotal();
        this.items = page.getResult();
    }

    public PageBean(Integer currentPage, Integer pageSize, Long totalNum) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalNum = totalNum;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(Long totalNum) {
        if(totalNum >= 0){
            this.totalNum = totalNum;
            if(this.currentPage > Math.ceil(this.totalNum.doubleValue() / this.pageSize)){
                this.currentPage = (int)(this.totalNum / this.pageSize);
            }
            if(this.currentPage <= 0) {
                this.currentPage = 1;
            }
        }else {
            this.totalNum = 0L;
        }
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }
}
